<?php

namespace Biz\model\brandActivity;

use Biz\pockets\constInterface\BlindBoxConfig;
use Doraemon\pockets\datebase\BaseDbModel;

class BlindBoxChangeRecord extends BaseDbModel implements BlindBoxConfig
{
    const _CONFIG_FILE_ = 'db_store';

    const _CONFIG_SELECT_ = 'db_brand_activity';

    const _DATABASE_ = 'brand_activity';

    const _TABLE_NAME = 'blind_box_change_record';

    const CHANGE_TYPE_SYS = 0;//系统生成（每天第一次进盲盒，随机生成一个盲盒id）
    const CHANGE_TYPE_OPEN_BOX = 1;//打开盲盒
    const CHANGE_TYPE_POINT = 2;//用户主动使用积分更换盲盒

    public static function getByWhere($where, $select = '*')
    {
        return self::get($select, $where);
    }

    public static function selectByWhere($where, $select = '*')
    {
        $list = self::select($select, $where);
        return $list;
    }

    public static function selectCountWhere($where)
    {
        $count = self::count('id', $where);
        return $count;
    }

    public static function insertData($data)
    {
        if (!isset($data['addtime'])) {
            $data['addtime'] = date('Y-m-d H:i:s');
        }
        $ret = self::insert($data);
        if ($ret->errorCode() !== '00000') {
            return false;
        }
        return self::id();
    }

    public static function updateData($data, $where)
    {
        $ret = self::update($data, $where);
        if ($ret->errorCode() !== '00000') {
            return false;
        }
        return true;
    }
}